Mapkit SwiftUI iOS17

I am trying to load and view several locations onto a map from a JSOPN file in my SwiftUI project, but I continually encounter the error "no exact matches in call to initializer" in my ContentView.swift file.

What I Am Trying to Do: I am working on a SwiftUI project where I need to display several locations on a map. These locations are stored in a JSON file, which I have successfully loaded into Swift. My goal is to display these locations as annotations on a Map view.

JSON File Contents: coordinates: latitude and longitude name: name of the location uuid: unique identifier for each location Code and Screenshots: Here are the relevant parts of my code and the error I keep encountering: import SwiftUI import MapKit

struct ContentView: View { @State private var mapPosition = MapCameraPosition.region( MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194), span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05) ) ) @State private var features: [Feature] = []

var body: some View {
    NavigationView {
        Map(position: $mapPosition, interactionModes: .all, showsUserLocation: true) {
            ForEach(features) { feature in
                Marker(coordinate: feature.coordinate) {
                    FeatureAnnotation(feature: feature)
                }
            }
        }
        .onAppear {
            POILoader.loadPOIs { result in
                switch result {
                case .success(let features):
                    self.features = features
                case .failure(let error):
                    print("Error loading POIs: \(error.localizedDescription)")
                }
            }
        }
        .navigationBarTitle("POI Map", displayMode: .inline)
    }
}

}

struct FeatureAnnotation: View { let feature: Feature

var body: some View {
    VStack {
        Circle()
            .strokeBorder(Color.red, lineWidth: 2)
            .background(Circle().foregroundColor(.red))
            .frame(width: 20, height: 20)
        Text(feature.name)
    }
}

} I have not had any luck searching for solutions to my problems using the error messages that keep arising. Does anyone have any advice for how to move forward?

3 more files/views attached to the project.

The error is telling you that there is no such form of Map that matches what you've entered.

If you remove showsUserLocation: true it works, because that form of Map() is valid.

If you want to show the user's location you need to use UserAnnotation(), i.e.;

Map(position: $mapPosition, interactionModes: .all) {
  UserAnnotation()  // <<-- Use this
  ForEach(features) { feature in
    Marker(coordinate: feature.coordinate) {
      FeatureAnnotation(feature: feature)
    }
  }
}
Mapkit SwiftUI iOS17
 
 
Q